import 'dart:async';

import 'package:fish_redux/fish_redux.dart';

import 'action.dart';
import 'state.dart';

Effect<EcologyState> buildEffect() {
  return combineEffects(<Object, Effect<EcologyState>>{
    EcologyAction.action: _onAction,
    Lifecycle.initState: _initState,
  });
}

void _onAction(Action action, Context<EcologyState> ctx) {}

void _initState(Action action, Context<EcologyState> ctx) {
  var timer = Timer.periodic(Duration(milliseconds: 80), (timer) {
    // ignore: invalid_use_of_protected_member
    if (ctx.state.controller.positions.isNotEmpty) {
      ctx.state.controller.animateTo(ctx.state.controller.offset + 1);
    }
  });

  // ctx.state.controller.addListener(() {
  //   print(ctx.state.controller.offset); //打印滚动位置
  //   if (ctx.state.controller.offset >= 100) {
  //     timer.cancel();
  //     ctx.state.controller.jumpTo(.0);
  //     timer = Timer.periodic(Duration(milliseconds: 80), (timer) {
  //       // ignore: invalid_use_of_protected_member
  //       if (ctx.state.controller.positions.isNotEmpty) {
  //         ctx.state.controller.animateTo(ctx.state.controller.offset + 1);
  //       }
  //     });
  //   }
  // });
}